<!-- 数字区间 -->
<template>
	<span>
		<el-form-item :label="label">
            <el-input v-model="startVal" class="number-scope" type="number" @input="changeStartNum"></el-input>-
            <el-input v-model="endVal" class="number-scope" type="number" @input="changeEndNum"></el-input>
        </el-form-item>
	</span>
</template>

<script type="text/javascript">
	export default {
		name: 'elFormNumScope',
		data(){
			return {
				startVal:'',
				endVal:''
			}
		},
		props: {
			label: {type: String, default:'--' },
			data: { type: Object},
			startName: { type: String},
			endName: { type: String}
		},
		created(){
			this.startVal = this.data[this.startName];
			this.endVal = this.data[this.endName];
			/*this.$on('form-add', field => {
				if(field)
					this.fields.push(field);
			});
			this.$on('form-remove', field => {
				if(field.prop)
					this.fields.splice(this.fields.indexOf(field), 1);
			});*/
		},
		methods:{
            changeStartNum(e){
            	setTimeout(() =>{
				    if(this.checkVal()){
	            		this.data[this.startName] = this.startVal;	
	            	}
				}, 500);
            },
            changeEndNum(e){
            	setTimeout(() =>{
					if(this.checkVal()){
	            		this.data[this.endName] = this.endVal;
	            	}    
				}, 500);
            },
            checkVal(){
            	let v1 = this.startVal;
            	let v2 = this.endVal;
            	if(!v1 || v1<0){
            		this.msg.error("起始数字不能为空或者小于0");
            		this.startVal=0;
            		return false;
            	}
            	if(!v2 || v2<0){
					this.msg.error("结束数字不能为空或者小于0");
					this.endVal= this.startVal || 0;
					return false;
            	}
            	if(parseInt(v1) > parseInt(v2)){
            		this.msg.error("起始数字不能大于结束数字");
            		this.startVal=this.endVal;
            		return false;
            	}
            	return true;
            }
        }
	}
</script>